package com.hs.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.hs.room.model.archive.OptLog
import kotlinx.coroutines.flow.Flow

@Dao
interface OptLogDao {

    @Insert
    fun insert(d: OptLog)

    @Update
    fun update(d: OptLog): Int

    @Query("SELECT * FROM opt_log where :name = byName")
    fun selectByName(name: String): OptLog

    @Query("SELECT * FROM opt_log")
    fun getAll(): Flow<List<OptLog>>

    @Query("SELECT * FROM opt_log ORDER BY localId LIMIT :limit OFFSET :offset ")
    fun get(limit: Int, offset: Int): Flow<List<OptLog>>

    @Query("SELECT count(*) FROM opt_log")
    fun count(): Int

    @Delete
    fun delete(d: OptLog)

    @Query("SELECT * FROM opt_log ORDER BY localId DESC LIMIT 1")
    fun getLast(): OptLog
}